package com.example.zhengchaojun.arcgis.basicesTest.adapter;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.esri.arcgisruntime.concurrent.ListenableFuture;
import com.esri.arcgisruntime.data.Feature;
import com.esri.arcgisruntime.layers.FeatureLayer;
import com.esri.arcgisruntime.symbology.Symbol;
import com.example.zhengchaojun.arcgis.R;
import com.example.zhengchaojun.arcgis.baseadapter.ListViewBaseAdapter;

import java.util.List;


/**
 * 类描述：显示轨迹的ListView的adapter
 * 作者：郑朝军 on 2017/12/25
 * 邮箱：1250393285@qq.com
 * 公司：武汉智博创享科技有限公司
 * 修改人：郑朝军 on 2017/12/25
 * 修改备注：
 */
public class AlertLayerListAdapter extends ListViewBaseAdapter<Feature>
{
    private View m_view;

    public AlertLayerListAdapter(Activity activity, List<Feature> list)
    {
        super(activity, list);
    }

    public View getView(final int position, View convertView, ViewGroup parent)
    {
        convertView = getItemView(convertView, R.layout.widget_view_layer_managet_legent_item, parent);

        ImageView imageView = getView(convertView, R.id.widget_view_layer_managet_legent_item_img);
        final TextView tv_text = getView(convertView, R.id.widget_view_layer_managet_legent_item_txtName);

        final FeatureLayer track = getItem(position).getFeatureTable().getFeatureLayer();

        Feature feature = track.getFeatureTable().createFeature();
        Symbol symbol = track.getRenderer().getSymbol(feature);
        ListenableFuture<Bitmap> listenableFuture = symbol.createSwatchAsync(activity, Color.RED);
        try
        {
            imageView.setImageBitmap(listenableFuture.get());
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
        tv_text.setText(track.getName());
        return convertView;
    }
}
